package dp;

public class Singleton {

	private static final Singleton singleton;
	private int compteur;

	static {
		singleton = new Singleton();
	}

	private Singleton() {
		System.out.println("Instanciation du singleton");
	}

	public static Singleton getInstance() {
		return singleton;
	}

	public /* synchronized */ void traiter(String taskName) {
		System.out.println("......Traitement de la tache " + taskName);
		for (int i = 1; i <= 5; i++) {
			synchronized (this) {
				++compteur;
			}
			System.out.println(".." + compteur);
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println("Fin de " + taskName + ", compteur=" + compteur);
	}
}
